﻿<%@ WebHandler Language="C#" Class="GetCategory" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using BusinessObjects.BO_GetObjects;

public class GetCategory : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string Category = context.Request.QueryString["Category"];

        DataTable dt = BO_Categories.GetMenu(Convert.ToInt32(Category));
        StringBuilder strArticles = new StringBuilder();

        if (dt != null)
        {
            strArticles.Append("{ Category:[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strArticles.Append("{");
                strArticles.Append("\"Name\":\"" + dt.Rows[i]["FULL_CATEGORY_NAME"].ToString() + "\",");
                strArticles.Append("\"Id\":\"" + dt.Rows[i]["CATEGORY_ID"].ToString() + "\"");
                if (i != dt.Rows.Count - 1)
                {
                    strArticles.Append("},");
                }
            }
        }
        strArticles.Append("}");
        strArticles.Append("]}");
        context.Response.ContentType = "application/json";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.Write(strArticles.ToString());
        context.Response.End();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}